Giter VIP home page Giter VIP logo

pong's People

Contributors

coltonoscopy avatar dmalan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pong's Issues

all errors

A lot of errors, the code needs an update

pong-2 renders white screen

running 'love .' in pong-2 results in a completely white screen. With love.graphics.clear(40, 45, 52, 255) commented out everything works expect the background color is black rather then grey. I'm using love 11.1 on a 32bit Windows 10 machine.

pong3

Error

Syntax error: main.lua:23: '}' expected (to close '{' at line 21) near 'resizable'

Traceback

[C]: at 0x5999d550
[C]: in function 'require'
[C]: in function 'xpcall'
[C]: in function 'xpcall'

SetColor not working as demonstrated

In lecture during presentation of pong-6 (fps update), new function was introduced:
love.graphics.setColor(0, 255/255, 0, 255/255)
In love2d this "new" color should persist between frames (or calls to love.draw function)
But in this example it seems each frame defaults back to white color, without explicitly calling love.graphics.setColor

I highly suspect push library is an actual reason behind this, especially line love.graphics.setColor(white, white, white) which is called during "push:finish" function, which is actually called with push:apply('end')

setColour in displayFPS() does not work right

The FPS counter is not visible in pong-6, pong-7, pong-8, pong-11 and pong-12.

The line love.graphics.setColor(0, 255/255, 0, 255/255) in function displayFPS() in main.lua is wrong. pong-10 and pong-11 have the correct line love.graphics.setColor(0, 255, 0, 255), the colours are in range 0-255, not 0.0-1.0.

Observed in Ubuntu Linux 18.04, Love 0.9.1-4.

Better ball velocity in `Ball.lua` class

In pong-5/Ball,lua, the ball velocity along the x-axis and y-axis is not so good compared to pong-4. The ball will either has -100 or 100 velocity along y-axis but will have a random velocity from -50 to 50 along x-axis. As a result, the ball movement is unnatural and does not look like random (we have longer x distance and less y distance. It will be more natural if the x-axis velocity is a fixed big number and y-axis velocity is a random relatively small number). This issue affects all programs with the Ball.lua class. Namely, from pong-5 to pong-12. The issue will be more obvious with the interaction with paddles since the ball x-axis velocity can be captured as drastically being faster or slower after colliding with the paddle (again, the reason is that we have a long x distance).

function Ball:reset()
    self.x = VIRTUAL_WIDTH / 2 - 2
    self.y = VIRTUAL_HEIGHT / 2 - 2
    self.dy = math.random(2) == 1 and -100 or 100
    self.dx = math.random(-50, 50)
end

However, in pong-4/main.lua, it will look like the ball is having a natural and random movement.

function love.keypressed(key)
    -- keys can be accessed by string name
    if key == 'escape' then
        -- function LÖVE gives us to terminate application
        love.event.quit()
    -- if we press enter during the start state of the game, we'll go into play mode
    -- during play mode, the ball will move in a random direction
    elseif key == 'enter' or key == 'return' then
        if gameState == 'start' then
            gameState = 'play'
        else
            gameState = 'start'
            
            -- start ball's position in the middle of the screen
            ballX = VIRTUAL_WIDTH / 2 - 2
            ballY = VIRTUAL_HEIGHT / 2 - 2

            -- given ball's x and y velocity a random starting value
            -- the and/or pattern here is Lua's way of accomplishing a ternary operation
            -- in other programming languages like C
            ballDX = math.random(2) == 1 and 100 or -100
            ballDY = math.random(-50, 50) * 1.5
        end
    end
end

In summary, the dx and dy velocity of ball in all Ball.lua class should be swapped.

Links in the CS50 page is obsolete

Hi @coltonoscopy,

I just followed the CS50 Game (after finishing the CS50 Intro to Computer Science) and about to start doing my first assignment. First of all, I am very impressed with everything about the lecture. From the way you are teaching, your slides, programming languages selection, and the assignments. Can't wait to finish all the lectures and assignments. After finishing the course I am planning to create mobile games and deploy them on the App stores.

However, I want to report 2 (minor) things regarding the course materials.

  1. The URL to the older Löve distributions (https://bitbucket.org/rude/love/downloads/) that is posted in the CS50 page (https://cs50.harvard.edu/games/2018/assignments/0/) is no longer valid.
  2. I noticed that you have updated your source code here to be compatible with the latest Löve's version, however, again, the source code provided in the CS50 page is still the older one (cdn.cs50.net/games/2019/x/assignments/0/assignment0.zip).

I was having problem with running your old source code, didn't know what was wrong, and finally managed to get it run thanks to this repo - after spending some time figuring out what was the problem. So, my humble request is, it would be nice to post this latest source code to the CS50 page so that new students won't have to struggle with this same issue anymore.

Thank you and all the best,
Jauhari

Pong 1

i have been having this issues any time i try to run main.lua despite having push.lua in the same folder
errror

Problems with pong 2 and on

Pong 0 and Pong 1 work fine, but from Pong 2 and on, it's just a plain white screen with no letters or words.

Read the Syllabus - Use Love ver 0.10.2

For anyone else who is new to this course and is experiencing all of the issues that other users are posting about - please read the Assignment0 text.

I was getting frustrated from experiencing all of the same issues that were being described here. I probably did the same thing all of you did - I started the video and downloaded Love2d, installed it with the video on pause, then came here and clicked download. Then I had issues.

However, after longer than I would care to admit (couple of hours) I read through the Assignment0 and it says to use Love2D build 0.10.2 and provides a link to download older versions of the software. I did this, and now everything works exactly as the class intends, with no issues.

I don't know if it will upgrade to the newer versions of Love2d as the class progresses or not, but if I can save anyone else the hassle, I hope this helps.

Code is not working on Visual Studio code

I am using visual studio code, as the instructor in first lecture,
but it didn't work
and i got this message
Exception has occurred: [C]:-1: attempt to index a nil value (global 'love')
stack traceback:
main.lua:29: in main chunk
[C]: in ?

Pong take one

import pygame
import sys

Initialize Pygame

pygame.init()

Constants

WIDTH, HEIGHT = 600, 400
BALL_SPEED = 5
PADDLE_SPEED = 8

Colors

WHITE = (255, 255, 255)
BLACK = (0, 0, 0)

Create the screen

screen = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption("Pong Game")

Create paddles and ball

player_paddle = pygame.Rect(50, HEIGHT // 2 - 25, 15, 50)
opponent_paddle = pygame.Rect(WIDTH - 65, HEIGHT // 2 - 25, 15, 50)
ball = pygame.Rect(WIDTH // 2 - 10, HEIGHT // 2 - 10, 20, 20)

Set initial ball direction

ball_direction = [1, 1]

Game loop

while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()

# Move paddles
keys = pygame.key.get_pressed()
if keys[pygame.K_w] and player_paddle.top > 0:
    player_paddle.y -= PADDLE_SPEED
if keys[pygame.K_s] and player_paddle.bottom < HEIGHT:
    player_paddle.y += PADDLE_SPEED

# Update ball position
ball.x += BALL_SPEED * ball_direction[0]
ball.y += BALL_SPEED * ball_direction[1]

# Ball collision with walls
if ball.top <= 0 or ball.bottom >= HEIGHT:
    ball_direction[1] *= -1

# Ball collision with paddles
if ball.colliderect(player_paddle) or ball.colliderect(opponent_paddle):
    ball_direction[0] *= -1

# Draw everything on the screen
screen.fill(BLACK)
pygame.draw.rect(screen, WHITE, player_paddle)
pygame.draw.rect(screen, WHITE, opponent_paddle)
pygame.draw.ellipse(screen, WHITE, ball)

# Update the display
pygame.display.flip()

# Cap the frame rate
pygame.time.Clock().tick(60)

Löve2D version relevant to run or adjust the code

Hi!
It would be possible to make a issues for all things that do not run as expected with the current version of Löve, but an easier path, I think would be to just put a comment in the README.md about the version that was used for this code so that people trying to run it can either use the older version or look for what changed between that and the current one.
Thanks for this great course!

pong 0

how to run pong 0 after writing code in visual studio code?

pong 1 issue boot.lua no code to run for Mac users

Error

[love "boot.lua"]:321: No code to run
Your game might be packaged incorrectly.
Make sure main.lua is at the top level of the zip.

Traceback

[love "callbacks.lua"]:228: in function 'handler'
[C]: in function 'error'
[C]: in function 'xpcall'
[C]: in function 'xpcall' #80

Paddle class errors

At first, there is the attempt to call global 'Class' (a nil value), which is an error, and then there is the "Attempt to index local self(a number value)" which, if you run the exact code colton used, still appears. Requires an update.

Problem with Love: Pong 2 and beyond

I was greeted with the following upon running Pong 2:

Error

push.lua:101: attempt to call field 'getPixelScale' (a nil value)

Traceback

push.lua:101: in function 'initValues'
push.lua:48: in function 'setupScreen'
main.lua:49: in function 'load'
[C]: in function 'xpcall'
[C]: in function 'xpcall'

I ran the other pongs and only pong1 and pong0 are unaffected. It seems to be a problem with getPixelScale, perhaps the system has changed so that this part of the code is less viable?

Pong 2

The font file font.ttf
From where do I create it? It's showing error in mine as the file is not in the folder and I am facing problems.
Please reply asap

ERROR
Error

Could not open file font.ttf. Does not exist.

Traceback

[C]: at 0x7ffef12bca30
[C]: in function 'newFont'
main.lua:14: in function 'load'
[C]: in function 'xpcall'
[C]: in function 'xpcall'

Love.graphics.clear white screen.

Hey in Pong-2, calling love.graphics.clear in love.draw makes the whole screen white. Commenting it out fixes it.

It's using the color 40, 45, 52, 255.

Further testing: moving it to a new push start/end doesn't work. Changing the color to full 255's doesn't work.

Update: Changing alpha to 0 at least makes the screen contents show. Doesn't apply the color though (alpha 0).

underlines

I am new here ofcourse. I am getting underlines on love. and variables. It does not have problem compiling but its annoying. Any help would be much appreciated.

pong1

i have been facing the problem . how to get push library functions

Error

main.lua:2: module 'push' not found:
no field package.preload['push']
no 'push' in LOVE game directories.
no file 'push' in LOVE paths.
no file '.\push.lua'
no file 'C:\Program Files\LOVE\lua\push.lua'
no file 'C:\Program Files\LOVE\lua\push\init.lua'
no file 'C:\Program Files (x86)\Lua\5.1\lua\push.luac'
no file '.\push.dll'
no file 'C:\Program Files\LOVE\push.dll'
no file 'C:\Program Files\LOVE\loadall.dll'

Traceback

[C]: in function 'require'
main.lua:2: in main chunk
[C]: in function 'require'
[C]: in function 'xpcall'
[C]: in function 'xpcall'

Screenshot (22)

help me out

Support keypad in Linux

The example does not work with keypad arrows and Enter in Linux. Could you add support for them? This requires changing 3 conditions in main.lua:

In function love.update replace
love.keyboard.isDown('up') with love.keyboard.isDown('up') or love.keyboard.isDown('kp8')
love.keyboard.isDown('down') with love.keyboard.isDown('down') or love.keyboard.isDown('kp2')

In function love.keypressed replace
key == 'enter' or key == 'return' with key == 'enter' or key == 'return' or key == 'kpenter'

LOVE framework 0.11.0 and newer issues

My solution was downloading a far older version: 0.10.2 . Of course, this is a far from ideal solution. Therefore, I'd like to identify all the possible sintaxis compatibility issues with newer versions.

Problems in Pong7

Whenever I try to change the state to the play state, I get an error message saying Error main.lua:42: attempt to call method 'collides' (a nil value).

Here's my code so far:

main.lua:

WINDOW_WIDTH = 1280
WINDOW_HEIGHT = 720

VIRTUAL_WIDTH = 432
VIRTUAL_HEIGHT = 243

PADDLE_SPEED = 200

push = require 'push'
Class = require 'class'

require 'Ball'
require 'Paddle'

function love.load()
    math.randomseed(os.time())
    love.graphics.setDefaultFilter('nearest', 'nearest')
    
    smallFont = love.graphics.newFont('font.ttf', 8)
    scoreFont = love.graphics.newFont('font.ttf', 32)

    player1Score = 0
    player2Score = 0

    player1 = Paddle(5, 20, 5, 20)
    player2 = Paddle(VIRTUAL_WIDTH - 10, VIRTUAL_HEIGHT - 30, 5, 20)
    ball = Ball(VIRTUAL_WIDTH / 2 - 2, VIRTUAL_HEIGHT / 2 - 2, 5, 5)

    gameState = 'start'

    push:setupScreen(VIRTUAL_WIDTH, VIRTUAL_HEIGHT, WINDOW_WIDTH, WINDOW_HEIGHT, {
        fullscreen = false,
        vsync = true,
        resizable = false
    })
end

function love.update(dt)
    if gameState == 'play' then 
        ball:update(dt)

        if ball:collides(player1) then
            ball.dx = -ball.dx
        end
        if ball:collides(player2) then
            ball.dx = -ball.dx
        end
        if ball.y <= 0 then
            ball.dy = -ball.dy
            ball.y = 0
        end
        if ball.y >= VIRTUAL_HEIGHT - 5 then
            ball.dy = -ball.dy
            ball.y = VIRTUAL_HEIGHT - 4
        end
    end
    
    player1:update(dt)
    player2:update(dt)

    if love.keyboard.isDown('w') then
        player1.dy = -PADDLE_SPEED
    elseif love.keyboard.isDown('s') then
        player1.dy = PADDLE_SPEED
    else 
        player1.dy = 0
    end

    if love.keyboard.isDown('up') then
        player2.dy = -PADDLE_SPEED
    elseif love.keyboard.isDown('down') then
        player2.dy = PADDLE_SPEED
    else
        player2.dy = 0
    end
end    

function love.keypressed(key)
    if key == 'escape' then
        love.event.quit()

    elseif key == 'enter' or key == 'return' then
        if gameState == 'start' then
            gameState = 'play'
        elseif gameState == 'play' then
            gameState = 'start'
            ball:reset()
        end
    end   
end   

function love.draw()
    push:apply('start') 

    love.graphics.clear(40 / 255, 45 / 255, 52 / 255, 255 / 255)
    
    ball:render(VIRTUAL_WIDTH / 2 - 2, VIRTUAL_HEIGHT / 2 - 2, 5, 5)
    player1:render(5, 20, 5, 20)
    player2:render(VIRTUAL_WIDTH - 10, VIRTUAL_HEIGHT - 30, 5, 20)    

    love.graphics.setFont(smallFont)
    if gameState == 'start' then
        love.graphics.printf(
            "Hello, Start State!", 
            0, 20, 
            VIRTUAL_WIDTH, 
            'center')
    elseif gameState == 'play' then
        love.graphics.printf(
            "Hello, Play State!", 
            0, 20, 
            VIRTUAL_WIDTH, 
            'center')
    end    
    love.graphics.setFont(scoreFont)
    love.graphics.print(
        player1Score, 
        VIRTUAL_WIDTH / 2 - 50, 
        VIRTUAL_HEIGHT / 3)      
    love.graphics.print(
        player2Score, 
        VIRTUAL_WIDTH / 2 + 30, 
        VIRTUAL_HEIGHT / 3)              

    displayFPS()

    push:apply('end')
end  

function displayFPS()
    love.graphics.setColor(0, 1, 0 ,1)
    love.graphics.setFont(smallFont)
    love.graphics.print('FPS: ' .. tostring(love.timer.getFPS()), 40, 20)
    love.graphics.setColor(1, 1, 1, 1)
end

Ball.lua

Ball = Class{}

function Ball:init(x, y, width, height)
    self.x = x
    self.y = y
    self.width = width
    self.height = height
    self.dx = math.random(2) == 1 and -100 or 100
    self.dy = math.random(-50, 50)
end

function Ball:collides(box)
    if self.x > box.x + box.width or self.x + self.width < box.x then
        return false
    end
    if self.y > box.y + box.height or self.y + self.height < box.y then
        return false
    end
    return true
end

function Ball:reset()
    self.x = VIRTUAL_WIDTH / 2 - 2
    self.y = VIRTUAL_HEIGHT / 2 -2

    self.dx = math.random(2) == 1 and -100 or 100
    self.dy = math.random(-50, 50)
end

function Ball:update(dt)
    self.x = self.x + self.dx * dt 
    self.y = self.y + self.dy * dt
end

function Ball:render()
    love.graphics.rectangle('fill', self.x, self.y, self.width, self.height)
end```

//edited to fix formatting

PONG 11 .wav file not opening

.wav file not opening. It gives an error of :
Error
Could not open WAVE
Traceback
[C]: at 0x010aa4e810
[C]: in function 'newSource'
main.lua:32: in function 'load'
[C]: in function 'xpcall'
[C]: in function 'xpcall'

Pong - 3, no visual

Hey guys, I'm running into an issue where I've gone over my push.lua and main.lua files, but when I load the Pong folder into Love 2D I dont get errors but I just get a white screen. Can anyone please help?

Cannot load game due to location.

This is what our error said
Error

boot.lua:577: Cannot load game at path '/Applications/src0/pong/pong-0/main.lua'.
Make sure a folder exists at the specified path.

Traceback

[C]: in function 'error'
[C]: in function 'xpcall'
[C]: in function 'xpcall'
Thanks

Push library issue for both love 11.1 and 11.3

Hi,

Using Linux Manjaro, following error when trying to run pong.1

-> Error: push.lua:116: attempt to perform arithmetic on field '_RWIDTH' (a table value)
stack traceback:
[string "boot.lua"]:777: in function '__div'
push.lua:116: in function 'initValues'
push.lua:54: in function 'setupScreen'
main.lua:24: in function 'load'
[string "boot.lua"]:586: in function <[string "boot.lua"]:585>
[C]: in function 'xpcall'
[string "boot.lua"]:793: in function <[string "boot.lua"]:780>
[C]: in function 'xpcall'

Not familiar with Lua and it's table system. I have tried using both the lua file maintained locally here, and the one maintained by Ulys. Both have this issue. Using love version 11.1 and 11.3, both have the same issue.

Anyone able to help?

My own idiocy, Problem fixed.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.